package com.lqe.mapper;

import com.lqe.pojo.Order;
import com.lqe.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface OrderMapper {
    @Select("select * from t_order")
    @Results({
            @Result(id = true,column = "id",property = "orderId"),
            @Result(column = "orderName",property = "orderName"),
            @Result(column = "orderMount",property = "orderMount"),
            @Result(column = "description",property = "description"),
            @Result(
                    column = "uid",
                    property = "user",
                    javaType = User.class,
                    one = @One(select = "com.lqe.mapper.UserMapper.queryUserById")
            )
    })
    List<Order> queryOrderAndUser();

    @Select("select * from t_order where id = #{id}")
    Order queryOrderByid(int id);

    @Select("select *,id orderId from t_order where userId = #{uid}")
    List<Order> queryOrderByUid(int uid);

    @Insert("insert into t_order values(null,#{orderName},#{orderMount},#{description},#{user.userId})")
    void insertOrder(Order order);

    @Delete("delete from t_order where id =#{id}")
    void deleteOrderById(int id);


}
